package com.hxn.wxshake.utils;

import com.alibaba.fastjson.JSONObject;
import com.hxn.wxshake.bean.Data;

import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @ClassName ListSort
 * @Description TODO
 * @Author hxn
 * @Date 2019/8/2 11:49
 * @Version 1.0
 **/
public class ListSort {

    /**
     * @Author hxn
     * @Description 对list进行升序排列
     * @Param
     * @return
     **/
    public static List<Data> sortByValue(List<Object> values) {
        return values.stream().map(obj -> cover(obj)).sorted(Comparator.comparing(Data::getNum)).collect(Collectors.toList());
    }
    /**
     * @Author hxn
     * @Description 对list进行降序排列
     * @Param
     * @return
     **/
    public static List<Data> sortByValueByDescSubStringKey(List<Object> values) {
        return values.stream().map(obj -> cover(obj)).sorted(Comparator.comparing(Data::getNum).reversed()).collect(Collectors.toList());
    }

    private static Data cover(Object obj){
        String objStr = String.valueOf(obj);
        String[] split = objStr.split("-");
        return new Data(split[0],split[1],split[2]);
    }

}
